<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>组件的事件传递</title>
		<script src="../vue@3.2.23.js"></script>
	</head>
	<body>
		<div id="app">
			<div class="count">父组件的计数器：{{count}}</div>
			<counter :count="count" @count-add="countAdd"></counter>
		</div>
	</body>
</html>
<script>
	// 事件传递:子组件向父组件传递
	// 父组件向子组件专递的值是单向的，不可在子组件中修改
	const app = Vue.createApp({
		data() {
			return {
				count:20
			}
		},
		methods:{
			countAdd(val,val2){
				console.log(val,val2);
				
				this.count += 1
			}
		}
	});
	app.component('counter',{
		props:["count"],
		// 事件声明
		emits:["countAdd"],
		methods:{
			changeCount(){
				// 事件传递
				this.$emit('countAdd',this.count+1,this.count+2)
			}
		},
		template:
		`
			<div>子组件的计数器：{{count}}</div>
			<button @click="changeCount">修改count</button>
		`
	})
	const vm = app.mount("#app")
</script>